function SelectActicleClassifyList() {
    $.ajax({
        url: httpurl + "/ProductTypeAllList",
        cache: false,
        async: false,
        data: {
            "type": 1
        },
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType: 'application/json',
        success: function(data) {
            if (data.rtnCode == 200) {
                let dataList = data.data;
                let info = '<option value="0">请选择</option>';
                for (let i = 0; i < dataList.length; i++) {
                    info += '<option value="' + dataList[i].id + '">' + dataList[i].name + '</option>';
                }
                $("#ClassifyList").html(info);
            }
        }
    })
}

function chooseThis(obj) {
    let dataId = $(obj).data("id");
    if ($.inArray(dataId, listId) > -1) {
        listId.splice($.inArray(dataId, listId), 1);
        $(obj).addClass("btn-info");
        $(obj).removeClass("btn-danger");
        $(obj).html("选取");
    } else {
        listId.push(dataId);
        $(obj).addClass("btn-danger");
        $(obj).removeClass("btn-info");
        $(obj).html("已选取");
    }
}
//查询所有类型
function TypelistByTypeId(typeId) {
    $.ajax({
        url: httpurl + "/ProductTypeAllList",
        cache: false,
        async: false,
        data: {
            "type": typeId
        },
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType: 'application/json',
        success: function(data) {
            var dataList = data.data;
            var typeinfo = "";
            if (data.rtnCode == 200) {
                typeinfo += '<option value="0">请选择</option>';
                for (var i = 0; i < dataList.length; i++) {
                    typeinfo += '<option value="' + dataList[i].id + '">' + dataList[i].name + '</option>';
                }
                $("#types").html(typeinfo);
            }
        },
        error: function(data) {
            top.layer.alert("类型搜索访问接口失败！！", function(index) {
                layer.close(index);
            });
        }
    });
}
/**
 * 查询所有角色
 * @constructor
 */
function SelectRoleList() {
    $.ajax({
        url: httpurl + "/SelectRoleList",
        cache: false,
        async: false,
        data: {
            "page": 1,
            "pagesize": 0,
        },
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType: 'application/json',
        success: function(data) {
            let dataInfo = data.data;
            let info = '<option value="0">请选择</option>';
            for (let i = 0; i < dataInfo.length; i++) {
                info += '<option value="' + dataInfo[i].id + '">' + dataInfo[i].roleName + '</option>';
            }
            $("#RoleList").html(info);
        }
    })
}
/**
 * 批量删除
 */
function DeleteInfoList(obj) {
    let checkedIdList = "";
    let UrlTarget = $(obj).attr("data-info");

    $(".aceChild").each(function() {
        if ($(this).is(':checked')) {
            checkedIdList += $(this).attr("data-id") + ",";
        }
    })
    if (checkedIdList.length <= 0) {
        layer.msg("请选择要删除的值");
        return;
    }
    checkedIdList = checkedIdList.substring(0, checkedIdList.length - 1);
    DeleteAjaxHttp(checkedIdList, UrlTarget);
}

function DeleteAjaxHttp(checkedIdList, UrlTarget) {
    top.layer.confirm('是否确定删除？删除后不可恢复哟!!', { icon: 3, title: '提示信息' }, function(index) {
        var index = top.layer.msg('提交中，请稍候', { icon: 16, time: false, shade: 0.8 });
        setTimeout(function() {
            $.ajax({
                type: "get",
                url: httpurl + "/" + UrlTarget,
                cache: false,
                data: {
                    "id": checkedIdList
                },
                traditional: true,
                headers: {
                    "Access-Control-Allow-Origin": "*",
                    "Access-Control-Allow-Methods": "*",
                    "Access-Control-Allow-Headers": "Authorization",
                    "Authorization": GetTokenInfo()
                },
                contentType: 'application/json',
                success: function(data) {
                    top.layer.closeAll();
                    top.layer.msg(data.msg);
                    onloadInfo();
                }
            });
        }, 1000);
    })
}

function DeleteInfo(obj) {
    let id = $(obj).attr("data-id");
    let UrlTarget = $(obj).attr("data-info");
    DeleteAjaxHttp(id, UrlTarget);
}

let listId = [];

function selectAllProductInfoByInfoPc() {
    let type = $("#types option:selected").val();
    let pronames = $("#pronames").val();
    $.ajax({
        url: httpurl + "/selectAllProductInfoByInfoPc",
        cache: false,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType: 'application/json',
        data: {
            "typeId": type,
            "pname": pronames,
            "pageNo": pageNo,
            "pageSize": pageSize
        },
        success: function(data) {
            let dataInfo = [];
            if (data.rtnCode == 200) {
                dataInfo = data.data.list;
                totalRecords = data.data.total;
            } else {
                totalRecords = 0;
            }
            table.render({
                elem: '#tableInfo',
                data: dataInfo,
                id: "tableInfoId",
                cols: [
                    [
                        { field: 'id', align: "center", width: 80, title: 'ID', sort: true }, { field: 'title', align: "center", title: '商品名称' }, {
                            field: 'headimg',
                            align: "center",
                            title: '商品图片',
                            sort: true,
                            templet: function(res) {
                                return (res == null ? "" : ("<img class='width20' src='" + visitimgurl + '/' + res.headimg + "'/>"));
                            }
                        }, {
                            field: 'del',
                            align: "center",
                            width: 150,
                            title: '操作',
                            unresize: true,
                            templet: function(res) {
                                let info = "";
                                if ($.inArray(res.id + "", listId) > -1) {
                                    info = '<span class="btn btn-danger choose_' + res.id + '" data-info="choose_' + res.id + '" data-id="' + res.id + '" onclick="chooseThis(this)">已选取</span>';
                                } else {
                                    info = '<span class="btn btn-info choose_' + res.id + '" data-info="choose_' + res.id + '" data-id="' + res.id + '" onclick="chooseThis(this)">选取</span>';
                                }
                                return info;
                            }
                        }
                    ]
                ]
            });
            pageLayPage("selectAllProductInfoByInfoPc");
        }
    });
}


//查询订单信息  付款  未付款 全部
function SelectOrderList() {
    $("#tableInfo tbody").html("");
    $.ajax({
        url: httpurl + "/selectOrderList",
        cache: false,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType: 'application/json',
        data: {
            "page": pageNo,
            "pagesize": pageRecords,
            "state": TempState
        },
        // dataType: "json",
        success: function(data) {
            // console.log("===="+JSON.stringify(data));
            let dataHtml = "";
            if (data.rtnCode == 200) {
                let initdata = data.data;
                totalRecords = initdata[initdata.length - 1].total;
                for (let i = 0; i < initdata.length; i++) {
                    dataHtml += '<tr class="text-primary">' +
                        '<td>' + initdata[i].id + '</td>' +
                        '<td>' + initdata[i].name + '</td>' +
                        '<td>' + initdata[i].phone + '</td>' +
                        '<td>' + initdata[i].ordermoney + '</td>' +
                        '<td>' + initdata[i].intime + '</td>' +
                        '<td>' + (initdata[i].state == 0 ? "待付款" : (initdata[i].state == 1 ? "待发货" : (initdata[i].state == 2 ? "待收货" : (initdata[i].state == 3 ? "已收货" : (initdata[i].state == 4 ? "售后" : "已取消"))))) + '</td>' +
                        '</tr>';
                }
            } else {
                dataHtml += '<tr>' +
                    '<td colspan="12" style="text-align:center;">暂无数据</td>' +
                    '</tr>';
            }
            $("#tableInfo tbody").html(dataHtml);
            layer.closeAll();
            page();
        }
    });
}

function onlyNumber(obj){
    var t = obj.value.charAt(0);
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d\.]/g,'');
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g,'');
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g,'.');
    //保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace('.','$#$').replace(/\./g,'').replace('$#$','.');
    //如果第一位是负号，则允许添加
    if(t == '-'){
        obj.value = '-'+obj.value;
    }
}